package com.ynding.spring.idea.ddd.biz.shared.wechat;

import com.ynding.spring.idea.ddd.common.service.facade.wechat.request.AssetReq;
import com.ynding.spring.idea.ddd.common.service.facade.wechat.request.WechatAccountReq;
import com.ynding.spring.idea.ddd.core.model.wechat.domain.WechatAccount;
import com.ynding.spring.idea.ddd.core.model.wechat.valobj.AssetVO;
import com.ynding.spring.idea.ddd.core.service.wechat.convert.AssetConvert;
import com.ynding.spring.idea.ddd.core.service.wechat.convert.WechatAccountConvert;
import com.ynding.spring.idea.ddd.core.service.wechat.service.TransferService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author ynding
 * @version 2022/9/3
 **/
@Component
@Slf4j
@RequiredArgsConstructor
public class TransferManage {

    private final TransferService transferService;

    /**
     * 微信转账业务
     *
     * @param payer 付款人
     * @param payee 收款人
     * @param asset 金额
     */
    public void transfer(WechatAccountReq payer, WechatAccountReq payee, AssetReq asset) {
        // 权限控制 TODO
        WechatAccount payerDP = WechatAccountConvert.convert(payer);
        WechatAccount payeeDP = WechatAccountConvert.convert(payee);
        AssetVO assetVO = AssetConvert.convert(asset);
        transferService.transfer(payerDP, payeeDP, assetVO);
    }
}
